package com.ruoyi.audit.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.PartnersInvite;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.audit.service.IPartnersInviteService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 合伙人邀请Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@RestController
@RequestMapping("/invite")
public class PartnersInviteController extends BaseController
{
    @Autowired
    private IPartnersInviteService partnersInviteService;

    /**
     * 查询合伙人邀请列表
     */
    @PreAuthorize(hasPermi = "audit:invite:list")
    @GetMapping("/list")
    public TableDataInfo list(PartnersInvite partnersInvite)
    {
        startPage();
        List<PartnersInvite> list = partnersInviteService.selectPartnersInviteList(partnersInvite);
        return getDataTable(list);
    }

    /**
     * 导出合伙人邀请列表
     */
    @PreAuthorize(hasPermi = "audit:invite:export")
    @Log(title = "合伙人邀请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartnersInvite partnersInvite) throws IOException
    {
        List<PartnersInvite> list = partnersInviteService.selectPartnersInviteList(partnersInvite);
        ExcelUtil<PartnersInvite> util = new ExcelUtil<PartnersInvite>(PartnersInvite.class);
        util.exportExcel(response, list, "invite");
    }

    /**
     * 获取合伙人邀请详细信息
     */
    @PreAuthorize(hasPermi = "audit:invite:query")
    @GetMapping(value = "/{inviteid}")
    public AjaxResult getInfo(@PathVariable("inviteid") Long inviteid)
    {
        return AjaxResult.success(partnersInviteService.selectPartnersInviteById(inviteid));
    }

    /**
     * 新增合伙人邀请
     */
    @PreAuthorize(hasPermi = "audit:invite:add")
    @Log(title = "合伙人邀请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartnersInvite partnersInvite)
    {
        return toAjax(partnersInviteService.insertPartnersInvite(partnersInvite));
    }

    /**
     * 修改合伙人邀请
     */
    @PreAuthorize(hasPermi = "audit:invite:edit")
    @Log(title = "合伙人邀请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartnersInvite partnersInvite)
    {
        return toAjax(partnersInviteService.updatePartnersInvite(partnersInvite));
    }

    /**
     * 删除合伙人邀请
     */
    @PreAuthorize(hasPermi = "audit:invite:remove")
    @Log(title = "合伙人邀请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inviteids}")
    public AjaxResult remove(@PathVariable Long[] inviteids)
    {
        return toAjax(partnersInviteService.deletePartnersInviteByIds(inviteids));
    }
}
